home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / plx13.zip / PLX.PAS < prev    next >
Pascal/Delphi Source File  |  1991-10-13  |  40KB  |  1,337 lines

  1. {Program Listing Express - Program Copyright (C) Doug Overmyer 9/2/91}
  2. {Begun 8/2/91}
  3. {1.1 9/15/91 change BN5, add sculpted static text fields }
  4. {1.2 9/23/91 revise printer method to eliminate double spacing of over-wide
  5.     lines;force enumeration and reselection of font after running control panel;
  6.     explicitly     dispose of Faces collection; better redraw of PSText objects}
  7. {1.3 10/5/91 avoid integer overflow on large margins, add change printer menu
  8.   item & button to printer dialog 10/1/91 Rework Font enumeration entirely,
  9.   move to Fonts unit, preload font size list box & hilite, add support for
  10.   bold & italic text, header & footer lines ; consolidate TPrinter subclasses into
  11.   printer1 unit;10/12/91 correct the file read logic to get last record of file w/o CRLF;
  12.   rework tab expand logic to move to tab columns rather than insert n spaces}
  13.  
  14. program PLXpress;
  15.  
  16. {$S-}
  17. {$R plx.RES}
  18. {$R-}
  19. uses WinTypes,WinProcs,Strings,WObjects,WOPlus,WFPlus,
  20.     Printer1,StdDlgs,Fonts;
  21.  
  22. const
  23.   cm_FOpen   = 101;     {menuitem FileOpen    }
  24.   cm_FPrint  = 102;     {menuitem FilePrint   }
  25.   cm_FSetUp  = 103;     {menuitem FilePageSetup}
  26.   cm_FExit   = 104;     {menuitem FileExit    }
  27.   cm_FChgPrt = 105;     {menuitem FileChangePrinter}
  28.   cm_TFont   = 111;     {menuitem TextFont    }
  29.   id_But1    = 201;     {User defined button 1 iconbar}
  30.   id_But2    = 202;     {      "             2 iconbar}
  31.   id_But3    = 203;     {      "             3 iconbar}
  32.   id_But4    = 204;     {      "             3 iconbar}
  33.   id_But5    = 205;     {      "             5 iconbar}
  34.   id_D1Lb1   = 301;     {List box element in Dlg1}
  35.   id_St1     = 401;     {Static text 1         icon bar}
  36.   id_St2     = 402;     {Static text 2         icon bar}
  37.   id_D3Setup = 501;     {Setup button in  Dlg3}
  38.   id_D3Change= 502;     {Change button in Dlg3}
  39.   id_D3OKPrt = 521;     {OK button in Dlg3    }
  40.   id_D2OK    = 601;     {OK button in Dlg2     }
  41.   id_D2EC1   = 603;     {Edit Control 1 in Dlg2 Margin.left}
  42.   id_D2EC2   = 605;     {             2         Margin.right}
  43.   id_D2EC3   = 607;     {             3         Margin.top}
  44.   id_D2EC4   = 609;     {             4         Margin.bottom}
  45.   id_D2EC5   = 617;     {             5         tabsize}
  46.   id_D2EC6   = 621;     {             6         Header text}
  47.   id_D2EC7   = 622;     {             7         Footer Text}
  48.   id_D2CB1   = 612;     {Check box 1 in Dlg2    Format.ShowRuler}
  49.   id_D2CB2   = 613;     {Check box 2 in Dlg2    Format.ShowFName}
  50.   id_D2CB3   = 614;     {Check box 3 in Dlg2    Format.ShowDTStamp}
  51.   id_D2CB4   = 615;     {Check box 4 in Dlg2    Format.ShowPageNum}
  52.   id_D2CB5   = 619;     {Check box 5 in Dlg2    Format.ShowLineNum}
  53.   id_D2CB6   = 620;     {Check box 6 in dlg2    format.UseCCB}
  54.   id_D4LB1     = 701;     {List box1  in Dlg4     font names}
  55.   id_D4LB2   = 702;     {List box2  in Dlg4     font sizes}
  56.   id_D4RB1   = 705;     {radio button 1 in Dlg4}  {font style normal}
  57.   id_D4RB2   = 706;     {radio button 2 in Dlg4}  {bold}
  58.   id_D4RB3   = 707;     {radio button 3 in Dlg4}  {italic}
  59.   idm_About  = 801;     {menu id for PLX_About menu}
  60.   idm_RunCP  = 802;     {menu id for run control panel}
  61.   um_FilePrint = 803;   {User defined message }
  62. {******************************************************************}
  63. { Types                                                            }
  64. {******************************************************************}
  65.  
  66. type
  67.     TPLXApplication = object(TApplication)
  68.   procedure InitMainWindow;virtual;
  69. end;
  70.  
  71. type
  72.     FormatRec = record
  73.   ShowRuler,ShowFName,ShowDTStamp,ShowPageNum,ShowLineNum,UseCCB:Integer;
  74.   Header,Footer:Array[0..132] of Char;
  75. end;
  76.  
  77. type
  78.     pFontStyleRec = ^FontStyleRec;
  79.   FontStyleRec = record
  80.       Normal,Bold,Italic:Integer;
  81. end;
  82.  
  83. PPLXDlg2 = ^TPLXDlg2;
  84. TPLXDlg2 = object(TDialog)              {Page setup dialog}
  85.     Margins:TRect;
  86.   Format:FormatRec;
  87.   TabSize:Integer;
  88.     procedure WMInitDialog(var Msg:TMessage);virtual wm_First+wm_InitDialog;
  89.   procedure IDD2OK(var Msg:TMessage); virtual id_First+id_D2OK;
  90.   procedure IDD2EC1(var Msg:TMessage);virtual id_First+id_D2EC1;
  91.   procedure IDD2EC2(var Msg:TMessage);virtual id_First+id_D2EC2;
  92.   procedure IDD2EC3(var Msg:TMessage);virtual id_First+id_D2EC3;
  93.   procedure IDD2EC4(var Msg:TMessage);virtual id_First+id_D2EC4;
  94.   procedure IDD2EC5(var Msg:TMessage);virtual id_First+id_D2EC5;
  95.   procedure IDD2EC6(var Msg:TMessage);virtual id_First+id_D2EC6;
  96.   procedure IDD2EC7(var Msg:TMessage);virtual id_First+id_D2EC7;
  97.   procedure IDD2CB1(var Msg:TMessage);virtual id_First+id_D2CB1;
  98.   procedure IDD2CB2(var Msg:TMessage);virtual id_First+id_D2CB2;
  99.   procedure IDD2CB3(var Msg:TMessage);virtual id_First+id_D2CB3;
  100.   procedure IDD2CB4(var Msg:TMessage);virtual id_First+id_D2CB4;
  101.   procedure IDD2CB5(var Msg:TMessage);virtual id_First+id_D2CB5;
  102.   procedure IDD2CB6(var Msg:TMessage);virtual id_First+id_D2CB6;
  103.     end;
  104.  
  105.  
  106. PPLXDlg3 = ^TPLXDlg3;
  107. TPLXDlg3 = object(TDialog)              {Print setup dialog}
  108.     procedure WMInitDialog(var Msg:TMessage);virtual wm_First+wm_InitDialog;
  109.   procedure IDSetup(var Msg:TMessage);virtual id_First+id_D3Setup;
  110.   procedure IDChange(var Msg:TMessage);virtual id_First+id_D3Change;
  111.   procedure IDOKPrt(var Msg:TMessage);virtual id_First+id_D3OKPrt;
  112.     end;
  113.  
  114. PPLXDlg4 = ^TPLXDlg4;                     {Type Faces & Sizes Dialog}
  115. TPLXDlg4 = object(TDialog)
  116.     FontSize: Integer;
  117.     procedure WMInitDialog(var Msg:TMessage);virtual wm_First+wm_InitDialog;
  118.   procedure IDD4Lb1(var Msg:TMessage);virtual id_First+id_D4Lb1;
  119.   procedure IDD4Lb2(var Msg:TMessage);virtual id_First+id_D4Lb2;
  120.   procedure IDD4RB1(var Msg:TMessage);virtual id_First+id_D4RB1;
  121.   procedure IDD4RB2(var Msg:TMessage);virtual id_First+id_D4RB2;
  122.   procedure IDD4RB3(var Msg:TMessage);virtual id_First+id_D4RB3;
  123.   procedure LoadSizes;virtual;
  124.     end;
  125.  
  126.  
  127. type
  128. pPLXPrinter = ^tPLXPrinter;
  129. tPlxPrinter = object(tPrinter1)
  130.     HeadLine1:Array[0..210] of Char;
  131.     function DoHeader:Boolean;virtual;
  132.   function DoFooter:Boolean;virtual;
  133.   function SetHeader1(NewHeadLine1:PChar):Boolean;virtual;
  134. end;
  135.  
  136.  
  137. type                           {MainWindow of Application}
  138. PPLXWindow = ^TPLXWindow;
  139. TPLXWindow = object(TWindow)
  140.     DispWin:PEdit;                   {child window displaying sample lines from infile}
  141.   TheIcon:HIcon;
  142.   Bn1,Bn2,Bn3,Bn4,Bn5 :PODButton;  {icon bar buttons}
  143.   FileName:Array[0..79] of Char;   {infile name}
  144.   CharsInFile:LongInt;             {chars in infile}
  145.   St1,St2:PSText;
  146.   FontSelection:Integer;   {Index into Fonts collection}
  147.   PFontSize:Integer;       {Current font size for printed text}
  148.   Records:PCollection;     {Collection of Infile records}
  149.   Margins:TRect;           {in inches * 100}
  150.   Format:FormatRec;        {format fields}
  151.   FontStyle:FontStyleRec;  {font style fields}
  152.   Tabsize:Integer;
  153.   Fonts:PFonts;            {font enumeration information}
  154.     constructor Init(AParent:PWindowsObject;ATitle:PChar);
  155.   destructor Done;virtual;
  156.   procedure SetupWindow;virtual;
  157.   procedure Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);virtual;
  158.   procedure SetStaticText;
  159.   procedure LoadDispWin;
  160.   procedure    WMDrawItem(var Msg:TMessage);virtual wm_First + wm_DrawItem;
  161.   procedure WMSize(var Msg:TMessage);virtual wm_First+wm_Size;
  162.   procedure WMSetFocus(var Msg:TMessage);virtual wm_First+wm_SetFocus;
  163.   procedure IDBut1(var Msg:TMessage);virtual id_First+id_But1; {Print}
  164.     procedure IDBut2(var Msg:TMessage);virtual id_First+id_But2; {FileOpen}
  165.   procedure IDBut3(var Msg:TMessage);virtual id_First+id_But3; {PageSetup}
  166.   procedure    IDBut4(var Msg:TMessage);virtual id_First+id_But4; {SelectFont}
  167.   procedure IDBut5(var Msg:TMessage);virtual id_First+id_But5; {Exit}
  168.   procedure EnumerateFonts;virtual;
  169.   function  GetFontSelection:Integer;virtual;
  170.   procedure SetFontSelection(NewSelection:Integer);
  171.   procedure    SetFontSize(NewfontSize:Integer);virtual;
  172.   procedure    SetPFontSize(NewfontSize:Integer);virtual;
  173.   procedure    UMFilePrint(var Msg:TMessage);virtual wm_User+um_FilePrint;
  174.   procedure    WMSysCommand(var Msg:TMessage);virtual wm_First+wm_SysCommand;
  175.   procedure CMFOpen(var Msg:TMessage);virtual cm_First+cm_FOpen;
  176.   procedure CMFPrint(var Msg:TMessage);virtual cm_First+cm_FPrint;
  177.     procedure CMFSetUp(var Msg:TMessage);virtual cm_First+cm_FSetUp;
  178.   procedure CMFChgPrt(var Msg:TMessage);virtual cm_First+cm_FChgPrt;
  179.     procedure CMFExit(var Msg:TMessage);virtual cm_First+cm_FExit;
  180.     procedure CMTFont(var Msg:TMessage);virtual cm_First+cm_TFont;
  181.   procedure GetFormatFlags(var AFormat:FormatRec);virtual;
  182.   procedure SetFormatFlags(NewFormat:FormatRec);virtual;
  183.   procedure GetMargins(var pMargins:PRect);virtual;
  184.   procedure SetMargins(NewMargins:TRect);virtual;
  185.   function  GetTabSize:Integer;virtual;
  186.   procedure SetTabSize(NewTabSize:Integer);virtual;
  187.   procedure GetProfileValues;virtual;
  188.   procedure WriteProfileValues;virtual;
  189.   procedure SetFontStyle(NewNormal,NewBold,NewItalic:Integer);virtual;
  190. end;
  191.  
  192. {********************************************************************}
  193. {G L O B A L  V A R I A B L E S                                      }
  194. {********************************************************************}
  195. var
  196.     MainWin:PPLXWindow;
  197. {********************************************************************}
  198. {M E T H O D S                                                       }
  199. {********************************************************************}
  200.  
  201. procedure TPLXApplication.InitMainWindow;
  202. begin
  203.     MainWindow := New(PPLXWindow,Init(nil,'PLX'));
  204.   MainWin := PPLXWindow(MainWindow);
  205. end;
  206.  
  207. {********************************************************************}
  208. {Init}
  209. constructor TPLXWindow.Init(AParent:PWindowsObject;ATitle:PChar);
  210. begin
  211.     TWindow.Init(AParent,ATitle);
  212.   Attr.Menu := LoadMenu(HInstance,'PLX_Menu');
  213.   Attr.X := 20; Attr.Y := 25; Attr.W := 595; Attr.H := 260;
  214.   Bn1 := New(PODButton,Init(@Self,id_But1,'Print',200,0,50,50,False,'PLX_Bn1'));
  215.   Bn2 := New(PODButton,Init(@Self,id_But2,'File Open',0,0,50,50,False,'PLX_Bn2'));
  216.   Bn3 := New(PODButton,Init(@Self,id_But3,'Page Setup',50,0,100,50,False,'PLX_Bn3'));
  217.   Bn4 := New(PODButton,Init(@Self,id_But4,'Font',150,0,50,50,False,'PLX_Bn4'));
  218.   Bn5 := New(PODButton,Init(@Self,id_But5,'Exit',250,0,50,50,False,'PLX_Bn5'));
  219.   St1 := New(PSText,Init(@Self,id_St1,'',315,3,240,20,sr_Recessed,dt_Center or dt_VCenter));
  220.   St2 := New(PSText,Init(@Self,id_St2,'',315,26,240,20,sr_Recessed,dt_Center or dt_VCenter));
  221.   FontSelection := 9999;
  222.   PFontsize := 10;
  223.   Fonts := New(PFonts,Init);
  224.   EnumerateFonts;
  225.   DispWin := New(PEdit,Init(@Self,200,nil,0,0,0,0,0,True));
  226.   with DispWin^.Attr do
  227.        Style := Style or es_NoHideSel ;
  228.   Records := New(PCollection,Init(1000,500));
  229.   CharsInFile := 0;
  230.   Margins.left := 0;Margins.right := 0;Margins.top := 0;Margins.bottom := 0;
  231.   Format.ShowRuler := 1;Format.ShowFName := 1;
  232.     Format.ShowDTStamp := 1;Format.ShowPageNum := 1;
  233.   Format.ShowLineNum := 1;Format.UseCCB := 0;
  234.   StrCopy(Format.Header,'');StrCopy(Format.Footer,'');
  235.   FontStyle.Normal := 1;FontStyle.Bold := 0;FontStyle.Italic := 0;
  236.   Tabsize := 2;
  237.   GetProfileValues;
  238. end;
  239.  
  240. {SetupWindow}
  241. procedure TPLXWindow.SetupWindow;
  242. var
  243.     SysMenu:hMenu;
  244.   OEMFixFont:hFont;
  245. begin
  246.     TWindow.SetupWindow;
  247.     SetClassWord(HWindow,GCW_HIcon,LoadIcon(HInstance,'PLX_Icon'));
  248.   Sysmenu := GetSystemMenu(hWindow,false);
  249.   AppendMenu(SysMenu,MF_Separator,0,nil);
  250.   AppendMenu(SysMenu,0,idm_RunCP,'Run Control Panel');
  251.   AppendMenu(Sysmenu,0,idm_About,'About...');
  252.   OEMFixFont := GetStockObject(OEM_Fixed_Font);
  253.   SendMessage(DispWin^.hWindow,wm_SetFont,OEMFixFont,LongInt(1));
  254. end;
  255.  
  256. {Paint}
  257. procedure TPLXWindow.Paint(PaintDC:HDC;var PaintInfo:TPaintStruct);
  258. var
  259.     ThePen:HPen;
  260.   TheBrush :HBrush;
  261.   OldBrush :HBrush;
  262.   OldPen:HPen;
  263. begin
  264.     TheBrush := GetStockObject(LtGray_Brush);
  265.     ThePen := CreatePen(ps_Solid,1,$00000000);
  266.   OldPen := SelectObject(PaintDC,ThePen);
  267.   OldBrush := SelectObject(PaintDC,TheBrush);
  268.   Rectangle(PaintDC,0,0,1024,50);
  269.   SelectObject(PaintDC,OldBrush);
  270.   SelectObject(PaintDC,OldPen);
  271.   DeleteObject(ThePen);
  272. end;
  273.  
  274. {Route the Ownerdraw msgs to correct object}
  275. procedure    TPLXWindow.WMDrawItem(var Msg:TMessage);
  276. var
  277.     PDIS : ^TDrawItemStruct;
  278. begin
  279.     PDIS := Pointer(Msg.lParam);
  280.     case PDIS^.CtlType of
  281.         odt_Button:
  282.         case PDIS^.CtlID of
  283.             id_But1 :Bn1^.DrawItem(Msg);
  284.             id_But2 :Bn2^.DrawItem(Msg);
  285.             id_But3 :Bn3^.DrawItem(Msg);
  286.             id_But4 :Bn4^.DrawItem(Msg);
  287.             id_But5 :Bn5^.DrawItem(Msg);
  288.         end;
  289.     end;
  290. end;
  291.  
  292. {Done}
  293. destructor TPLXWindow.Done;
  294. begin
  295.   if FontSelection <> 9999 then
  296.       WriteProfileValues;
  297.   Dispose(Fonts,Done);
  298.   Dispose(Records,Done);
  299.   TWindow.Done;
  300. end;
  301.  
  302. {WMSize}
  303. procedure TPLXWindow.WMSize(var Msg:TMessage);
  304. begin
  305.     SetWindowPos(DispWin^.HWindow,0,-1,50,
  306.        (Msg.LParamLo )+1,(Msg.LParamHi-50),swp_NoZOrder);
  307. end;
  308.  
  309. {WMSetFocus}
  310. procedure TPLXWindow.WMSetFocus(var Msg:TMessage);
  311. begin
  312.  
  313. end;
  314.  
  315. {IDBut1} {Print file dialog }
  316. procedure TPLXWindow.IDBut1(var Msg:TMessage);
  317. var
  318.     Dlg : PDialog;
  319. begin
  320.     Dlg :=New(PPLXDlg3,Init(@Self,'PLX_Dlg3'));
  321.     Application^.ExecDialog(Dlg);
  322. end;
  323.  
  324. {IDBut2} {run file open dialog box, load file}
  325. procedure TPLXWindow.IDBut2(var Msg:TMessage);
  326. var
  327.     Dlg1 :PFileDialog;
  328.   InFile :PTextStream;
  329.   InRecord:PChar;
  330.   ExpRecord:PChar;
  331.   PctMeter:PMeterWindow;
  332.   Division,Pctdone:Integer;
  333.   indx1 : Integer;
  334.   Indx2 : Integer;
  335.   hTab :Integer;
  336. begin
  337.     Division := 10;
  338.     StrCopy(FileName,'*.*');
  339.   InRecord :=MemAlloc(9999);
  340.   ExpRecord := MemAlloc(9999);
  341.   if Records^.Count > 0 then
  342.       begin
  343.       Dispose(Records,Done);
  344.     Records := New(PCollection,Init(1000,500));
  345.       end;
  346.   DispWin^.Clear;
  347.   Dlg1 := new(PfileDialog,Init(@Self,PChar(sd_FileOpen),@FileName));
  348.   If Application^.ExecDialog(Dlg1) <> id_OK then
  349.       begin
  350.          StrCopy(FileName,'');
  351.     exit;
  352.     end;
  353.   if StrIComp(FileName,'*.*') <> 0 then
  354.       begin
  355.     PctMeter := New(PMeterWindow,Init(@Self,'PLX - Reading File'));
  356.     Application^.MakeWindow(PctMeter);
  357.     PctMeter^.Draw(0);
  358.     InFile := New(PTextStream,Init(FileName,stOpen,1024));
  359.     CharsInFile := InFile^.CharsToRead;
  360.     While NOT InFile^.IsEOF do
  361.         begin
  362.         StrCopy(InRecord,InFile^.GetNext);
  363.       if InRecord = nil then          {avoid storing null pointers }
  364.         StrCopy(InRecord,' ');
  365.       Records^.Insert(New(PTextObj,Init(InRecord)));
  366.       if InFile^.GetPctDone > Division then
  367.           begin
  368.           PctMeter^.Draw(Division);
  369.           Inc(Division,10);
  370.           end;
  371.       end;
  372.       Dispose(PctMeter,Done);
  373.     end;
  374.   FreeMem(InRecord,9999);
  375.   FreeMem(ExpRecord,9999);
  376.   UpdateWindow(hWindow);        {get a redraw before loading preview window}
  377.   LoadDispWin;
  378. end;
  379.  
  380. {IDBut3}   {page setup}
  381. procedure TPLXWindow.IDBut3(var Msg:TMessage);
  382. var
  383.     TotChars:Integer;
  384. begin
  385.   Application^.ExecDialog(New(PPLXDlg2,Init(@Self,'PLX_Dlg2')));
  386.   InvalidateRect(DispWin^.HWindow,nil,True);
  387. end;
  388.  
  389. {IDBut4} {run font selection dialogs}
  390. procedure TPLXWindow.IDBut4(var Msg:TMessage);
  391. var
  392.     Dlg2:PPLXDlg4;
  393. begin
  394.     if Fonts^.Count = 0 then      {if necessary, enumerate fonts for current printer}
  395.       begin
  396.       EnumerateFonts;
  397.       end;
  398.     Dlg2 := new(PPLXDlg4,Init(@Self,'PLX_Dlg4'));
  399.   Application^.ExecDialog(Dlg2);
  400.     if FontSelection = 9999  then
  401.       begin
  402.       MessageBox(hWindow,'Please select a font size','Alert',mb_OK or mb_IconExclamation);
  403.     exit;
  404.     end;
  405. end;
  406.  
  407. {IdBut5}  {exit}
  408. procedure TPLXWindow.IDBut5(var Msg:TMessage);
  409. begin
  410.   SendMessage(HWindow,wm_Close,0,0);
  411. end;
  412.  
  413. { Collect all of Fonts supported by current system printer }
  414. procedure TPLXWindow.EnumerateFonts;
  415. var
  416.   ThePrinter:pWOPrinter;
  417. begin
  418.   ThePrinter := New(pWOPrinter,Init(hInstance,@Self));
  419.   Fonts^.Enumerate(ThePrinter^.GetQuickDC);
  420.   ThePrinter^.DeleteQuickDC;
  421.   Dispose(ThePrinter,Done);
  422. end;
  423.  
  424. {GetFontSelection}
  425. function TPLXWindow.GetFontSelection:Integer;
  426. begin
  427.     GetFontSelection := FontSelection;
  428. end;
  429.  
  430. {SetFontSelection}
  431. procedure TPLXWindow.SetFontSelection(NewSelection:Integer);
  432. begin
  433.     FontSelection := NewSelection;
  434. end;
  435.  
  436. {SetFontSize}
  437. procedure TPLXWindow.SetFontSize(NewFontSize:Integer);
  438. begin
  439.     PFontSize := NewFontSize;
  440. end;
  441.  
  442. {SetPFontSize}
  443. procedure TPLXWindow.SetPFontSize(NewFontSize:Integer);
  444. begin
  445.     PFontSize := NewFontSize;
  446. end;
  447.  
  448. {UMFilePrint}
  449. procedure TPLXWindow.UMFilePrint(var Msg:TMessage);
  450. var
  451.     aPtr : pPLXPrinter;
  452.   indx : Integer;
  453.   FI : PFontItem;
  454.   OldFont,NewFont:hFont;
  455.   szSize:Array[0..7] of Char;
  456.   LogFont:TLogFont;
  457.   TM:TTextMetric;
  458.   Buf1,Buf2:PChar;
  459.   szIndx:Array[0..5] of Char;
  460.   OutRecord:pTextObj;
  461.   ExpRec:PChar;
  462.   CCB:Char;
  463. begin
  464.     if Records^.Count = 0  then
  465.       begin
  466.       MessageBox(hWindow,'You need to open a file - click the disk icon',
  467.             'Alert',mb_OK or mb_IconExclamation);
  468.     exit;
  469.     end;
  470.     if FontSelection = 9999  then
  471.       begin
  472.       MessageBox(hWindow,'You need to select a font - click the font button',
  473.             'Alert',mb_OK or mb_IconExclamation);
  474.     exit;
  475.     end;
  476.     aPtr := New(pPLXPrinter,Init(hInstance,@Self));
  477.     indx := 0;
  478.   GetMem(Buf1,16000);
  479.   GetMem(ExpRec,16000);
  480.   if aPtr^.Start('PLX',hWindow) then
  481.       begin
  482.       aPtr^.SetMarginL(round(Margins.left * (Fonts^.LogPixX / 100))) ;{margin in device pixels}
  483.     FI := Fonts^.At(FontSelection);
  484.     FI^.LogFont.lfHeight := Round(PFontsize * (Fonts^.LogPixY / 72));
  485.     FI^.LogFont.lfWidth := 0;
  486.     if FontStyle.Bold = 1 then
  487.         FI^.LogFont.lfWeight := fw_Bold
  488.         else
  489.             FI^.LogFont.lfWeight := fw_Normal;
  490.     if FontStyle.Italic = 1 then
  491.         FI^.LogFont.lfItalic := 1
  492.         else
  493.             FI^.LogFont.lfItalic := 0;
  494.     FI^.LogFont.lfQuality := Draft_Quality;
  495.     NewFont := CreateFontIndirect(FI^.LogFont);
  496.     OldFont := aPtr^.SetFont(NewFont);
  497.     aPtr^.SetHeader1(FileName);
  498.     aPtr^.SetupPage;
  499.     StrCopy(szIndx,'');
  500.  
  501.     for indx := 0 to  (Records^.Count-1) do
  502.         begin
  503.       OutRecord := Records^.AT(indx);
  504.       if OutRecord^.Text <> nil then           {avoid null pointer}
  505.           StrCopy(Buf1,OutRecord^.Text)
  506.       else
  507.           StrCopy(Buf1,'');
  508.       Buf2 := Buf1;
  509.       if Format.ShowLineNum = 1 then          {setup line numbers}
  510.           Str((indx+1):5,szIndx)
  511.       else
  512.           StrCopy(szIndx,'');
  513.       if (Format.UseCCB = 1)  then            {setup CCB for linespacing}
  514.         begin
  515.         CCB := Buf1[0];
  516.         Buf2:= Buf1+1;
  517.         end
  518.       else
  519.           CCB := ' ';
  520.             ExpandTabs(Buf2,ExpRec,Tabsize);                {expand tabs}
  521.             StrCat(StrCat(StrCopy(Buf1,szIndx),' '),ExpRec);
  522.  
  523.       case CCB of                         {do line spacing using CCB}
  524.                 '1':    aPtr^.NewPage;
  525.                 '0':    aPtr^.PrintLine(' ');
  526.                 '-':    begin
  527.                             aPtr^.PrintLine(' ');
  528.                             aPtr^.PrintLine(' ');
  529.               end;
  530.         end;
  531.       aPtr^.printLine(Buf1);
  532.       end;
  533.  
  534.       aPtr^.PrtMode := pm_PrintFooter;        {do one last footer}
  535.       APtr^.DoFooter;
  536.       OldFont := aPtr^.SetFont(OldFont);      {restore the old font}
  537.       DeleteObject(NewFont);
  538.       aPtr^.Finish;
  539.       Dispose(aPtr,Done);
  540.     end; {end if}
  541.   FreeMem(Buf1,16000);
  542.   FreeMem(ExpRec,16000);
  543. end;
  544.  
  545. {WMSysCommand}
  546. procedure    TPLXWindow.WMSysCommand(var Msg:TMessage);
  547. begin
  548.     case Msg.Wparam of
  549.         idm_About:
  550.             Application^.ExecDialog(New(PDialog,Init(@Self,'PLX_About')));
  551.     idm_RunCP:
  552.             begin
  553.         WinExec('Control',1);
  554.       FontSelection := 9999;    {Force a reselection of current font}
  555.       PFontSize := 10;
  556.       Fonts^.ReInit;            {reinitialze the collections }
  557.         end;
  558.        else
  559.            DefWndProc(Msg);
  560.        end;
  561. end;
  562.  
  563. {SetStaticText}
  564. procedure TPLXWindow.SetStaticText;
  565. var
  566.   I: Integer;
  567.   Buf:Array[0..80] of Char;
  568.   szLines:Array[0..5] of Char;
  569.   LPY:Integer;
  570.   FontMetrics:TTextMetric;
  571.   szBytes:Array[0..7] of Char;
  572.   nBytes:Integer;
  573. begin                                             {build text display}
  574.   StrCopy(Buf,'File: ');
  575.     St1^.SetText(StrCat(Buf,FileName));
  576.   Str(CharsInFile:5,szBytes);
  577.   Str(Records^.Count:5,szLines);
  578.   StrECopy(StrECopy(StrECopy(StrECopy(Buf,'# of Lines:'),szLines),'  Bytes:'),szBytes);
  579.   St2^.SetText(Buf);
  580. end;
  581.  
  582. {LoadDispWin}
  583. procedure TPLXWindow.LoadDispWin;
  584. var
  585.     InRecord:PTextObj;
  586.   Indx:Integer;
  587.   Buf1:pChar;
  588.   Cursor:hCursor;
  589.   CRLF :Array[0..2] of Char;
  590.   RCount:Integer;
  591. begin
  592.     StrCopy(CRLF,#13#10#0);
  593.   RCount := Records^.Count;
  594.     if RCount > 0 then
  595.        begin
  596.       SetCursor(LoadCursor(0,Idc_Wait));
  597.       indx := 0;
  598.       DispWin^.Clear;
  599.       GetMem(Buf1,27000);
  600.       StrCopy(Buf1,'');
  601.       while (indx < 100) AND (indx < RCount) AND (StrLen(Buf1) < 15000) do
  602.           begin
  603.         InRecord := Records^.At(indx);
  604.         If InRecord^.Text <> NIL then
  605.             StrCat(StrCat(Buf1,InRecord^.Text),CRLF)
  606.         else
  607.              StrCat(Buf1,CRLF) ;
  608.           Inc(indx,1);
  609.           end;
  610.       if (StrLen(Buf1) > 14999) or (Indx > 99)  then
  611.           begin
  612.           StrCat(Buf1,CRLF);
  613.           StrCat(StrCat(Buf1,'... Rest of text not displayed!!!'),CRLF);
  614.         end;
  615.       DispWin^.Insert(Buf1);
  616.       FreeMem(Buf1,27000);
  617.       DispWin^.Scroll(0,-9999);
  618.       SetCursor(LoadCursor(0,Idc_Arrow));
  619.       SetStaticText;
  620.        end;
  621. end;
  622.  
  623. {CMFOpen}
  624. procedure TPLXWindow.CMFOpen(var Msg:TMessage);
  625. begin
  626.     IDBut2(Msg);
  627. end;
  628.  
  629. {CMFPrint}
  630. procedure TPLXWindow.CMFPrint(var Msg:TMessage);
  631. begin
  632.     IDBut1(Msg);
  633.   end;
  634.  
  635. {CMFSetup}
  636. procedure TPLXWindow.CMFSetUp(var Msg:TMessage);
  637. begin
  638.     IDBut3(Msg);
  639. end;
  640.  
  641. {CMFExit}
  642. procedure TPLXWindow.CMFExit(var Msg:TMessage);
  643. begin
  644.     IDBut5(Msg);
  645. end;
  646.  
  647. {CMFChgPrt}
  648. procedure TPLXWindow.CMFChgPrt(var Msg:TMessage);
  649. var
  650.     ThePrinter:pWOPrinter;
  651. begin
  652.     ThePrinter := New(pWOPrinter,Init(hInstance,@Self));
  653.   ThePrinter^.ChgPrinter;
  654.   Dispose(ThePrinter,Done);
  655.   FontSelection := 9999;
  656.   PFontSize := 10;
  657.   Fonts^.ReInit;
  658. end;
  659.  
  660. {CMTFont}
  661. procedure TPLXWindow.CMTFont(var Msg:TMessage);
  662. begin
  663.     IDBut4(Msg);
  664. end;
  665.  
  666.  
  667. procedure TPLXWindow.GetFormatFlags(var AFormat:FormatRec);
  668. begin
  669.     AFormat.ShowRuler := Format.ShowRuler;
  670.     AFormat.ShowFName := Format.ShowFName;
  671.     AFormat.ShowDTStamp := Format.ShowDTStamp;
  672.     AFormat.ShowPageNum := Format.ShowPageNum;
  673.     AFormat.ShowLineNum := Format.ShowLineNum;
  674.   AFormat.UseCCB      := Format.UseCCB;
  675.   StrCopy(AFormat.Header,Format.Header);
  676.   StrCopy(AFormat.Footer,Format.Footer);
  677. end;
  678.  
  679. procedure TPLXWindow.SetFormatFlags(NewFormat:FormatRec);
  680. begin
  681.     Format.ShowRuler := NewFormat.ShowRuler;
  682.   Format.ShowFName := NewFormat.ShowFName;
  683.   Format.ShowDTStamp := NewFormat.ShowDTStamp;
  684.   Format.ShowPageNum := NewFormat.ShowPageNum;
  685.   Format.ShowLineNum := NewFormat.ShowLineNum;
  686.   Format.UseCCB := NewFormat.UseCCB;
  687.   StrCopy(Format.Header,NewFormat.Header);
  688.   StrCopy(Format.Footer,NewFormat.Footer);
  689. end;
  690.  
  691.  
  692. procedure TPLXWindow.GetMargins(var pMargins:PRect);
  693. begin
  694.     pMargins^.Left := Margins.left;
  695.   pMargins^.Right := Margins.right;
  696.   pMargins^.Top := Margins.Top;
  697.   pMargins^.Bottom := Margins.Bottom;
  698. end;
  699.  
  700. procedure TPLXWindow.SetMargins(NewMargins:TRect);
  701. begin
  702.     Margins.left := NewMargins.left;
  703.   Margins.right := NewMargins.right;
  704.   Margins.top := NewMargins.top;
  705.   Margins.Bottom := NewMargins.bottom;
  706. end;
  707.  
  708. function TPLXWindow.GetTabSize:Integer;
  709. begin
  710.     GetTabSize := TabSize;
  711. end;
  712.  
  713. procedure TPLXWindow.SetTabSize(NewTabSize:Integer);
  714. begin
  715.     TabSize := NewTabSize;
  716. end;
  717.  
  718. procedure TPLXWindow.GetProfileValues;
  719. var
  720.     Buf1:Array[0..30] of Char;
  721.   Indx:Integer;
  722.   Item:PFontItem;
  723.   Found:Boolean;
  724. begin
  725.     Format.ShowRuler := GetPrivateProfileInt('PLX','ShowRuler',1,'PLX.INI');
  726.     Format.ShowFName := GetPrivateProfileInt('PLX','ShowFName',1,'PLX.INI');
  727.     Format.ShowDTStamp := GetPrivateProfileInt('PLX','ShowDTStamp',1,'PLX.INI');
  728.     Format.ShowPageNum := GetPrivateProfileInt('PLX','ShowPageNum',1,'PLX.INI');
  729.     Format.ShowLineNum := GetPrivateProfileInt('PLX','ShowLineNum',1,'PLX.INI');
  730.     Format.UseCCB := GetPrivateProfileInt('PLX','UseCCB',0,'PLX.INI');
  731.  
  732.     Margins.Left := GetPrivateProfileInt('PLX','MarginL',0,'PLX.INI');
  733.     Margins.Right := GetPrivateProfileInt('PLX','MarginR',0,'PLX.INI');
  734.     Margins.Top := GetPrivateProfileInt('PLX','MarginT',0,'PLX.INI');
  735.     Margins.Bottom := GetPrivateProfileInt('PLX','MarginB',0,'PLX.INI');
  736.     TabSize := GetPrivateProfileInt('PLX','TabSize',2,'PLX.INI');
  737.  
  738.   FontStyle.Normal := GetPrivateProfileInt('PLX','Normal',1,'PLX.INI');
  739.   FontStyle.Bold := GetPrivateProfileInt('PLX','Bold',0,'PLX.INI');
  740.   FontStyle.Italic := GetPrivateProfileInt('PLX','Italic',0,'PLX.INI');
  741.  
  742.  
  743.     GetPrivateProfileString('PLX','FaceName','9999',Buf1,SizeOf(Buf1),'PLX.INI');
  744.     PFontSize:= GetPrivateProfileInt('PLX','FontSize',8,'PLX.INI');
  745.     Found := False;
  746.     for Indx := 0 to Fonts^.Count -1 do
  747.       begin
  748.     Item := Fonts^.At(Indx);
  749.     If (StrIComp(Item^.LogFont.lfFaceName,Buf1) = 0) then
  750.         begin
  751.       FontSelection := Indx;
  752.       Found := True;
  753.       end
  754.     end;
  755. end;
  756.  
  757. procedure TPLXWindow.WriteProfileValues;
  758. var
  759.     Buf:Array[0..5] of Char;
  760.   FI:pFontItem;
  761. begin
  762.     StrCopy(Buf,'');
  763.     FI := Fonts^.At(FontSelection);
  764.   WritePrivateProfileString('PLX','FaceName',FI^.LogFont.lfFaceName,'PLX.INI');
  765.   Str(PFontSize,Buf);
  766.   WritePrivateProfileString('PLX','FontSize',Buf,'PLX.INI');
  767.   Str(FontStyle.Normal,Buf);
  768.   WritePrivateProfileString('PLX','Normal',Buf,'PLX.INI');
  769.   Str(FontStyle.Bold,Buf);
  770.   WritePrivateProfileString('PLX','Bold',Buf,'PLX.INI');
  771.   Str(FontStyle.Italic,Buf);
  772.   WritePrivateProfileString('PLX','Italic',Buf,'PLX.INI');
  773.  
  774.   Str(Format.ShowRuler,Buf);
  775.   WritePrivateProfileString('PLX','ShowRuler',Buf,'PLX.INI');
  776.   Str(Format.ShowFName,Buf);
  777.   WritePrivateProfileString('PLX','ShowFName',Buf,'PLX.INI');
  778.   Str(Format.ShowDTStamp,Buf);
  779.   WritePrivateProfileString('PLX','ShowDTStamp',Buf,'PLX.INI');
  780.   Str(Format.ShowPageNum,Buf);
  781.   WritePrivateProfileString('PLX','ShowPageNum',Buf,'PLX.INI');
  782.   Str(Format.ShowLineNum,Buf);
  783.   WritePrivateProfileString('PLX','ShowLineNum',Buf,'PLX.INI');
  784.   Str(Format.UseCCB,Buf);
  785.   WritePrivateProfileString('PLX','UseCCB',Buf,'PLX.INI');
  786.  
  787.   Str(Margins.Left,Buf);
  788.   WritePrivateProfileString('PLX','MarginL',Buf,'PLX.INI');
  789.   Str(Margins.Right,Buf);
  790.   WritePrivateProfileString('PLX','MarginR',Buf,'PLX.INI');
  791.   Str(Margins.Top,Buf);
  792.   WritePrivateProfileString('PLX','MarginT',Buf,'PLX.INI');
  793.   Str(Margins.Bottom,Buf);
  794.   WritePrivateProfileString('PLX','MarginB',Buf,'PLX.INI');
  795.   Str(TabSize,Buf);
  796.   WritePrivateProfileString('PLX','TabSize',Buf,'PLX.INI');
  797. end;
  798.  
  799.  
  800. procedure TPLXWindow.SetFontStyle(NewNormal,NewBold,NewItalic:Integer);
  801. begin
  802.     FontStyle.Normal := NewNormal;
  803.   FontStyle.Bold := NewBold;
  804.   FontStyle.Italic := NewItalic;
  805. end;
  806.  
  807. {*********************************************************************}
  808. procedure TPLXDlg2.WMInitDialog(var Msg:TMessage);
  809. var
  810.     Buf1:Array[0..5] of Char;
  811.   pBuf:PChar;
  812.   pMargins : PRect;
  813. begin
  814.     pMargins := @Margins;
  815.     MainWin^.GetMargins(pMargins);
  816.   MainWin^.GetFormatFlags(Format);
  817.   TabSize := PPLXWindow(Parent)^.GetTabSize;
  818.     SendDlgItemMsg(id_D2CB1,bm_SetCheck,Format.ShowRuler,0);
  819.     SendDlgItemMsg(id_D2CB2,bm_SetCheck,Format.ShowFName,0);
  820.     SendDlgItemMsg(id_D2CB3,bm_SetCheck,Format.ShowDTStamp,0);
  821.     SendDlgItemMsg(id_D2CB4,bm_SetCheck,Format.ShowPageNum,0);
  822.     SendDlgItemMsg(id_D2CB5,bm_SetCheck,Format.ShowLineNum,0);
  823.     SendDlgItemMsg(id_D2CB6,bm_SetCheck,Format.UseCCB,0);
  824.  
  825.   pBuf := Buf1;
  826.   Str(Margins.Left/100:3:1,Buf1);
  827.   SendDlgItemMsg(id_D2EC1,wm_SetText,0,LongInt(pBuf));
  828.   Str(Margins.Right/100:3:1,Buf1);
  829.   SendDlgItemMsg(id_D2EC2,wm_SetText,0,LongInt(pBuf));
  830.   Str(Margins.Top/100:3:1,Buf1);
  831.   SendDlgItemMsg(id_D2EC3,wm_SetText,0,LongInt(pBuf));
  832.   Str(Margins.Bottom/100:3:1,Buf1);
  833.   SendDlgItemMsg(id_D2EC4,wm_SetText,0,LongInt(pBuf));
  834.   Str(TabSize,Buf1);
  835.   SendDlgItemMsg(id_D2EC5,wm_SetText,0,LongInt(pBuf));
  836.   StrCopy(Format.Header,'');
  837.   Strcopy(Format.Footer,'');
  838. end;
  839.  
  840. procedure TPLXDlg2.IDD2OK(var Msg:TMessage);
  841. begin
  842.   MainWin^.SetMargins(Margins);
  843.   MainWin^.SetFormatFlags(Format);
  844.   MainWin^.SetTabSize(TabSize);
  845.   EndDlg(1);
  846. end;
  847.  
  848. procedure TPLXDlg2.IDD2CB1(var Msg:TMessage);
  849. begin
  850.     case Msg.lParamHi of
  851.     bn_Clicked:
  852.            begin
  853.       Format.ShowRuler := SendDlgItemMsg(id_D2CB1,bm_GetCheck,0,0);
  854.       Exit;
  855.       end;
  856.   end;
  857. end;
  858.  
  859. procedure TPLXDlg2.IDD2CB2(var Msg:TMessage);
  860. begin
  861.     case Msg.lParamHi of
  862.     bn_Clicked:
  863.            begin
  864.       Format.ShowFName := SendDlgItemMsg(id_D2CB2,bm_GetCheck,0,0);
  865.       Exit;
  866.       end;
  867.   end;
  868. end;
  869.  
  870. procedure TPLXDlg2.IDD2CB3(var Msg:TMessage);
  871. begin
  872.     case Msg.lParamHi of
  873.     bn_Clicked:
  874.            begin
  875.       Format.ShowDTStamp := SendDlgItemMsg(id_D2CB3,bm_GetCheck,0,0);
  876.       Exit;
  877.       end;
  878.   end;
  879. end;
  880.  
  881. procedure TPLXDlg2.IDD2CB4(var Msg:TMessage);
  882. begin
  883.     case Msg.lParamHi of
  884.     bn_Clicked:
  885.            begin
  886.       Format.ShowPageNum := SendDlgItemMsg(id_D2CB4,bm_GetCheck,0,0);
  887.       Exit;
  888.       end;
  889.   end;
  890. end;
  891.  
  892. procedure TPLXDlg2.IDD2CB5(var Msg:TMessage);
  893. begin
  894.     case Msg.lParamHi of
  895.     bn_Clicked:
  896.            begin
  897.       Format.ShowLineNum := SendDlgItemMsg(id_D2CB5,bm_GetCheck,0,0);
  898.       Exit;
  899.       end;
  900.   end;
  901. end;
  902.  
  903. procedure TPLXDlg2.IDD2CB6(var Msg:TMessage);
  904. begin
  905.     case Msg.lParamHi of
  906.     bn_Clicked:
  907.            begin
  908.       Format.UseCCB := SendDlgItemMsg(id_D2CB6,bm_GetCheck,0,0);
  909.       Exit;
  910.       end;
  911.   end;
  912. end;
  913.  
  914. procedure TPLXDlg2.IDD2EC1(var Msg:TMessage);
  915. var
  916.     Idx : Integer;
  917.   Buf:Array[0..5] of Char;
  918.   Ptr : PChar;
  919.   ErrCode:Integer;
  920.   Margin:Real;
  921.   return:Integer;
  922. begin
  923.     case Msg.lParamHi of
  924.     en_KillFocus:
  925.            begin
  926.       Ptr := Buf;
  927.       Idx := 5;
  928.       Return := SendDlgItemMsg(id_D2EC1,wm_GetText,word(Idx),LongInt(Ptr));
  929.       val(Ptr,Margin,ErrCode);
  930.       Margins.Left := round(Margin * 100);
  931.       Exit;
  932.       end;
  933.   end;
  934. end;
  935.  
  936. procedure TPLXDlg2.IDD2EC2(var Msg:TMessage);
  937. var
  938.     Idx : Integer;
  939.   Buf:Array[0..5] of Char;
  940.   Ptr : PChar;
  941.   ErrCode:Integer;
  942.   Margin:Real;
  943.   return:Integer;
  944. begin
  945.     case Msg.lParamHi of
  946.     en_KillFocus:
  947.        begin
  948.       Ptr := Buf;
  949.       Idx := 5;
  950.       Return := SendDlgItemMsg(id_D2EC2,wm_GetText,word(Idx),LongInt(Ptr));
  951.       val(Ptr,Margin,ErrCode);
  952.       Margins.Right := round(Margin * 100);
  953.       Exit;
  954.       end;
  955.    end;
  956. end ;
  957.  
  958. procedure TPLXDlg2.IDD2EC3(var Msg:TMessage);
  959. var
  960.     Idx : Integer;
  961.   Buf:Array[0..5] of Char;
  962.   Ptr : PChar;
  963.   ErrCode:Integer;
  964.   Margin:Real;
  965.   return:Integer;
  966. begin
  967.     case Msg.lParamHi of
  968.     en_KillFocus:
  969.        begin
  970.       Ptr := Buf;
  971.       Idx := 5;
  972.       Return := SendDlgItemMsg(id_D2EC3,wm_GetText,word(Idx),LongInt(Ptr));
  973.       val(Ptr,Margin,ErrCode);
  974.       Margins.Top := round(Margin * 100);
  975.       Exit;
  976.       end;
  977.    end;
  978. end;
  979.  
  980. procedure TPLXDlg2.IDD2EC4(var Msg:TMessage);
  981. var
  982.     Idx : Integer;
  983.   Buf:Array[0..5] of Char;
  984.   Ptr : PChar;
  985.   ErrCode:Integer;
  986.   Margin:Real;
  987.   return:Integer;
  988. begin
  989.     case Msg.lParamHi of
  990.     en_KillFocus:
  991.        begin
  992.       Ptr := Buf;
  993.       Idx := 5;
  994.       Return := SendDlgItemMsg(id_D2EC4,wm_GetText,word(Idx),LongInt(Ptr));
  995.       val(Ptr,Margin,ErrCode);
  996.       Margins.Bottom := round(Margin * 100);
  997.       Exit;
  998.       end;
  999.    end;
  1000. end;
  1001.  
  1002. procedure TPLXDlg2.IDD2EC5(var Msg:TMessage);
  1003. var
  1004.     Idx : Integer;
  1005.   Buf:Array[0..5] of Char;
  1006.   Ptr : PChar;
  1007.   ErrCode:Integer;
  1008.   TSize:Integer;
  1009.   return:Integer;
  1010. begin
  1011.     case Msg.lParamHi of
  1012.     en_KillFocus:
  1013.         begin
  1014.       Ptr := Buf;
  1015.       Idx := 5;
  1016.       Return := SendDlgItemMsg(id_D2EC5,wm_GetText,word(Idx),LongInt(Ptr));
  1017.       val(Ptr,TSize,ErrCode);
  1018.       TabSize := TSize;
  1019.       Exit;
  1020.       end;
  1021.    end;
  1022. end;
  1023.  
  1024. procedure TPLXDlg2.IDD2EC6(var Msg:TMessage);
  1025. var
  1026.     Idx : Integer;
  1027.   Buf:Array[0..132] of Char;
  1028.   Ptr : PChar;
  1029.   ErrCode:Integer;
  1030.   TSize:Integer;
  1031.   return:Integer;
  1032. begin
  1033.     case Msg.lParamHi of
  1034.     en_KillFocus:
  1035.         begin
  1036.       Ptr := Buf;
  1037.       Idx := 132;
  1038.       Return := SendDlgItemMsg(id_D2EC6,wm_GetText,word(Idx),LongInt(Ptr));
  1039.       StrCopy(Format.Header,Ptr);
  1040.       Exit;
  1041.       end;
  1042.    end;
  1043. end;
  1044.  
  1045. procedure TPLXDlg2.IDD2EC7(var Msg:TMessage);
  1046. var
  1047.     Idx : Integer;
  1048.   Buf:Array[0..132] of Char;
  1049.   Ptr : PChar;
  1050.   ErrCode:Integer;
  1051.   TSize:Integer;
  1052.   return:Integer;
  1053. begin
  1054.     case Msg.lParamHi of
  1055.     en_KillFocus:
  1056.         begin
  1057.       Ptr := Buf;
  1058.       Idx := 132;
  1059.       Return := SendDlgItemMsg(id_D2EC7,wm_GetText,word(Idx),LongInt(Ptr));
  1060.       StrCopy(Format.Footer,Ptr);
  1061.       Exit;
  1062.       end;
  1063.    end;
  1064. end;
  1065.  
  1066. {*********************************************************************}
  1067. procedure TPLXDlg3.WMInitDialog(var Msg:TMessage);
  1068. var
  1069.   ThePrinter:pWOPrinter;
  1070.   DeviceName:Array[0..40] of Char;
  1071. begin
  1072.      TDialog.WMInitDialog(Msg);
  1073.    ThePrinter := New(pWOPrinter,Init(hInstance,@Self));
  1074.    ThePrinter^.GetQuickDC;
  1075.    StrCopy(DeviceName,ThePrinter^.deviceName);
  1076.    ThePrinter^.DeleteQuickDC;
  1077.    Dispose(ThePrinter,Done);
  1078.    SetDlgItemText(HWindow,503,DeviceName);
  1079. end;
  1080.  
  1081. procedure TPLXDlg3.IDSetup(var Msg:TMessage);
  1082. var
  1083.     ThePrinter:pWOPrinter;
  1084. begin
  1085.     ThePrinter := New(pWOPrinter,Init(hInstance,@Self));
  1086.   ThePrinter^.prnDeviceMode(hWindow);
  1087.   dispose(ThePrinter,Done);
  1088.   MainWin^.FontSelection := 9999;
  1089.   MainWin^.PFontSize := 10;
  1090.   MainWin^.Fonts^.ReInit;
  1091. end;
  1092.  
  1093. procedure TPLXDlg3.IDChange(var Msg:TMessage);
  1094. begin
  1095.     EndDlg(1);
  1096.     SendMessage(MainWin^.HWindow,wm_Command,cm_FChgPrt,0);
  1097. end;
  1098.  
  1099.  procedure TPLXDlg3.IDOKPrt(var Msg:TMessage);
  1100. begin
  1101.     EndDlg(1);
  1102.     SendMessage(MainWin^.HWindow,wm_User+um_FilePrint,Msg.wParam,Msg.LParam);
  1103. end;
  1104.  
  1105. {***********************************************************************}
  1106.  
  1107. procedure TPLXDlg4.WMInitDialog(var Msg:TMessage);
  1108. var
  1109.     Indx : Integer;
  1110.   Font : PFontItem;
  1111.     pTextItem:PChar;
  1112.   szString:Array[0..5] of Char;
  1113. begin
  1114.     TDialog.WMInitDialog(Msg);
  1115.     for indx := 0 to (PPLXWindow(Parent)^.Fonts^.Count -1) do
  1116.        begin
  1117.         Font := MainWin^.Fonts^.At(indx);
  1118.     pTextItem :=  Font^.LogFont.lfFaceName;
  1119.     SendDlgItemMsg(id_D4LB1,lb_AddString,word(0),LongInt(pTextItem));
  1120.     end;
  1121.   IF MainWin^.FontSelection <> 9999 then
  1122.       begin
  1123.       SendDlgItemMsg(id_D4Lb1,lb_SetCurSel,MainWin^.FontSelection,0);
  1124.     LoadSizes;
  1125.     pTextItem := szString;
  1126.     Str(MainWin^.PFontSize:3,szString);
  1127.     SendDlgItemMsg(id_D4lb2,lb_SelectString,word(-1),LongInt(pTextItem));
  1128.     end;
  1129.   if MainWin^.FontStyle.Normal = 1 then
  1130.       SendDlgItemMsg(id_D4RB1,bm_SetCheck,1,0)
  1131.   else if MainWin^.FontStyle.Bold = 1 then
  1132.     SendDlgItemMsg(id_D4RB2,bm_SetCheck,1,0)
  1133.   else SendDlgItemMsg(id_D4RB3,bm_SetCheck,1,0);
  1134. end;
  1135.  
  1136. procedure TPLXDlg4.IDD4Lb1(var Msg:TMessage);
  1137. var
  1138.     Idx : Integer;
  1139.   Buf:Array[0..5] of Char;
  1140.   Ptr : PChar;
  1141.   ErrCode:Integer;
  1142. begin
  1143.     case Msg.lParamHi of
  1144.     lbn_SelChange,lbn_DblClk:
  1145.        begin
  1146.     Ptr := Buf;
  1147.     Idx := SendDlgItemMsg(id_D4Lb1,lb_GetCurSel,0,0);
  1148.     MainWin^.SetFontSelection(Idx);
  1149.     loadsizes;
  1150.     end;
  1151.    end;
  1152. end;
  1153.  
  1154. procedure TPLXDlg4.IDD4Lb2(var Msg:TMessage);
  1155. var
  1156.     Idx : Integer;
  1157.    Buf:Array[0..5] of Char;
  1158.    Ptr : PChar;
  1159.    ErrCode:Integer;
  1160. begin
  1161.     case Msg.lParamHi of
  1162.     lbn_SelChange,lbn_DblClk:
  1163.        begin
  1164.       Ptr := @Buf;
  1165.       Idx := SendDlgItemMsg(id_D4Lb2,lb_GetCurSel,0,0);
  1166.       SendDlgItemMsg(id_D4Lb2,lb_GetText,Idx,LongInt(Ptr));
  1167.       val(Ptr,FontSize,ErrCode);
  1168.       MainWin^.SetFontSize(FontSize);
  1169.       end;
  1170.    end;
  1171. end;
  1172.  
  1173. procedure TPLXDlg4.LoadSizes;
  1174. var
  1175.     pTextItem:PChar;
  1176.   Buf:Array[0..5] of Char;
  1177.     Indx,Indx2:Integer;
  1178.   FontItem:PFontItem;
  1179.   Item:PIntObj;
  1180.   Res,Res2:Integer;
  1181.   Height:Integer;
  1182.   LPY:Integer;
  1183. begin
  1184.   LPY := MainWin^.Fonts^.LogPixY;
  1185.   FontItem := MainWin^.Fonts^.At(MainWin^.GetFontSelection);
  1186.   Indx2 := 0;
  1187.   Indx := 6;
  1188.   pTextItem := Buf;
  1189.   Res := FontItem^.FontType and Raster_FontType; {0 = vector font}
  1190.   Res2 := FontItem^.FontType and Device_FontType; {0 = GDI font}
  1191.     SendDlgItemMsg(id_D4Lb2,lb_ResetContent,word(0),LongInt(pTextItem));
  1192.   if Res = 0 then
  1193.        begin
  1194.        Str(Indx:3,Buf);
  1195.        while Indx < 20 do
  1196.            begin
  1197.            SendDlgItemMsg(id_D4Lb2,lb_AddString,word(0),LongInt(pTextItem));
  1198.             Indx := Indx + 2;
  1199.         Str(Indx:3,Buf);
  1200.            end;
  1201.        end
  1202.   else
  1203.        for Indx2 := 0 to FontItem^.Sizes^.Count-1  do
  1204.         begin
  1205.       Item := FontItem^.Sizes^.At(Indx2);
  1206.       Height := Item^.Int;
  1207.       Str(Round(Height * 72 / LPY):3,Buf);
  1208.            SendDlgItemMsg(id_D4Lb2,lb_AddString,word(0),LongInt(pTextItem));
  1209.       end;
  1210. end;
  1211.  
  1212.  
  1213. procedure TPLXDlg4.IDD4RB1(var Msg:TMessage);  {Normal}
  1214. var
  1215.     Idx : Integer;
  1216. begin
  1217.     case Msg.lParamHi of
  1218.     bn_Clicked:
  1219.        begin
  1220.       Idx := SendDlgItemMsg(id_D4RB1,bm_GetCheck,0,0);
  1221.       if Idx = 0 then
  1222.            begin
  1223.                 SendDlgItemMsg(id_D4RB1,bm_SetCheck,1,0);
  1224.           SendDlgItemMsg(id_D4RB2,bm_SetCheck,0,0);
  1225.           SendDlgItemMsg(id_D4RB3,bm_SetCheck,0,0);
  1226.         MainWin^.SetFontStyle(1,0,0);
  1227.         end;
  1228.       end;
  1229.    end;
  1230. end;
  1231.  
  1232. procedure TPLXDlg4.IDD4RB2(var Msg:TMessage); {Bold}
  1233. var
  1234.     Idx : Integer;
  1235. begin
  1236.     case Msg.lParamHi of
  1237.     bn_Clicked:
  1238.        begin
  1239.       Idx := SendDlgItemMsg(id_D4RB2,bm_GetCheck,0,0);
  1240.       if Idx = 0 then
  1241.            begin
  1242.                 SendDlgItemMsg(id_D4RB2,bm_SetCheck,1,0);
  1243.           SendDlgItemMsg(id_D4RB1,bm_SetCheck,0,0);
  1244.           SendDlgItemMsg(id_D4RB3,bm_SetCheck,0,0);
  1245.         MainWin^.SetFontStyle(0,1,0);
  1246.         end;
  1247.       end;
  1248.    end;
  1249. end;
  1250.  
  1251. procedure TPLXDlg4.IDD4RB3(var Msg:TMessage);  {Italic}
  1252. var
  1253.     Idx : Integer;
  1254. begin
  1255.     case Msg.lParamHi of
  1256.     bn_Clicked:
  1257.        begin
  1258.       Idx := SendDlgItemMsg(id_D4RB3,bm_GetCheck,0,0);
  1259.       if Idx = 0 then
  1260.            begin
  1261.                 SendDlgItemMsg(id_D4RB3,bm_SetCheck,1,0);
  1262.           SendDlgItemMsg(id_D4RB1,bm_SetCheck,0,0);
  1263.           SendDlgItemMsg(id_D4RB2,bm_SetCheck,0,0);
  1264.         MainWin^.SetFontStyle(0,0,1);
  1265.         end;
  1266.       end;
  1267.    end;
  1268. end;
  1269. {***********************************************************************}
  1270. function  TPLXPrinter.DoHeader:Boolean;
  1271. var
  1272.     Indx : Integer;
  1273.     FI : PFontItem;
  1274.     szSize:Array[0..7] of Char;
  1275.     Buf1:Array[0..100] of Char;
  1276.     szDateTime:Array[0..79] of Char;
  1277.   szPageNumber:Array[0..5] of Char;
  1278.   Ruler : Array[0..260] of Char;
  1279.   Format:FormatRec;
  1280. begin
  1281.   MainWin^.GetFormatFlags(Format);
  1282.   if Format.ShowLineNum = 1 then
  1283.       StrCopy(Ruler,'     ')
  1284.   else
  1285.       StrCopy(Ruler,'');
  1286.     StrCat(Ruler,' |...+....1....+....2....+....3....+....4....+....5');
  1287.   StrCat(Ruler,'....+....6....+....7....+....8....+....9....+....0');
  1288.     StrCat(Ruler,'....+....1....+....2....+....3....+....4....+....5');
  1289.   StrCat(Ruler,'....+....6....+....7....+....8....+....9....+....0');
  1290.     StrCat(Ruler,'....+....1....+....2....+....3....+....4....+....5');
  1291.   ResetPos;
  1292.   if StrLen(Format.Header) <> 0 then
  1293.       printLine(Format.Header);
  1294.   StrCopy(Buf1,'');
  1295.   GetDateTime(szDateTime);
  1296.   if Format.ShowFName <> 0 then
  1297.       StrCopy(Buf1,HeadLine1);
  1298.   if Format.ShowDTStamp <> 0 then
  1299.       StrCat(StrCat(Buf1,'  '),szDateTime);
  1300.   Str(PageNumber:3,szPageNumber);
  1301.   if Format.ShowPageNum <> 0 then
  1302.       StrCat(StrCat(Buf1,'       page:'),szPageNumber);
  1303.   if StrLen(Buf1) <> 0 then
  1304.       print(Buf1);
  1305.   SetMarginL(Margin.left); {Set margin = 0 inch}
  1306.   NewLine;
  1307.   if Format.ShowRuler <> 0 then
  1308.       PrintLine(Ruler);
  1309. end;
  1310.  
  1311. function tPLXPrinter.SetHeader1(NewHeadLine1:PChar):Boolean;
  1312. begin
  1313.     StrCopy(HeadLine1,NewHeadLine1);
  1314.   SetHeader1 := True;
  1315. end;
  1316.  
  1317. function tPLXPrinter.DoFooter:Boolean;
  1318. var
  1319.   Format:FormatRec;
  1320. begin
  1321.     if PrtMode > pm_NoPrint then           {position footer at bottom of page}
  1322.         posY := MaxY - (Margin.Bottom +  FooterY + height);
  1323.   MainWin^.GetFormatFlags(Format);      {get Footer text, if any}
  1324.   if StrLen(Format.Footer) > 0 then
  1325.       PrintLine(Format.Footer);
  1326. end;
  1327. {*********************************************************************}
  1328. {*** M A I N L I N E                                                  }
  1329. {*********************************************************************}
  1330. var
  1331.     PLXApp : TPLXApplication;
  1332. begin
  1333.     PLXApp.Init('PLX');
  1334.     PLXApp.Run;
  1335.     PLXApp.Done;
  1336. end.
  1337.